﻿using System;
using System.Collections.Generic;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.ServiceModel.Activation;

using Semantics.Silverlight;
using Semantics.Remoting;

namespace NaturalWiki
{
    [ServiceContract(Namespace = "")]
    [SilverlightFaultBehavior]
    [AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
    public class ParserService : EOS.Security.WCFServiceBase
    {
        public static bool DesignMode = false;
        [OperationContract]
        public void DoWork()
        {
            // 在此处添加操作实现
            return;
        }

        //[OperationContract]
        //public List<Semantics.Silverlight.Sentence> GetSentences()
        //{
        //    List<Semantics.Silverlight.Sentence> sentences = Backend.ParseServer.TheServer.GetSentences();
        //    return sentences;
        //}

        //[OperationContract]
        //public ParseResult Parse(string words)
        //{
        //    ParseResult result = Backend.ParseServer.TheServer.Parse(words);
        //    return result;
        //}

        //[OperationContract]
        //public ParseResult SelectProcedure(int chilidKey, int selectIndex, string selectValue, string words, ParseResult result)
        //{
        //    return Backend.ParseServer.TheServer.SelectProcedure(chilidKey, selectIndex, selectValue, words, result);

        //}
        [OperationContract]
        public LanguageNode TestLangNode()
        {
            LanguageNode langnode = new LanguageNode("中国人民");// LanguageNode.LanguageNodeFromXml(e.Result);
            langnode.Children.Add(new LanguageNode("中国"));
            langnode.Children.Add(new LanguageNode("人民"));
            return langnode;
        }
        // 在此处添加更多操作并使用 [OperationContract] 标记它们
        [OperationContract]
        List<Semantics.Silverlight.Category> GetSubCategories(int nodeid)
        {
            return this.MentorProxy.GetSubCategories(nodeid);
        }

        NaturalWiki.Backend.RemotableMentorProxy _mentorproxy;
        NaturalWiki.Backend.RemotableMentorProxy MentorProxy
        {
            get
            {
                if (_mentorproxy == null)
                    _mentorproxy = WikiSystem.GetWikiSystem().GetMentorProxy();
                return _mentorproxy;
            }
        }
        [OperationContract]
        int CreateWord(string word, int categorynodeid)
        {
            return this.MentorProxy.CreateWord(word, categorynodeid);
        }
        [OperationContract]
        public List<Semantics.Silverlight.Category> SearchCategories(string word)
        {
            return this.MentorProxy.SearchCategories(word);
        }
        [OperationContract]
        public List<Semantics.Silverlight.Category> GetCategroyHierarchy(int nodeid)
        {
            if (DesignMode)
                return null;
            List<Semantics.Silverlight.Category> results = this.MentorProxy.GetCategroyHierarchy(nodeid);
            return results;
        }

        //[OperationContract]
        //public DialogueResult Dialogue(DialogueInput input)
        //{
        //    string contact = System.Web.HttpContext.Current.User.Identity.Name;
        //    DialogueResult result = SilverlightParser.Web.Backend.Reference.GetDialogueProxy(contact).Dialogue(input, contact);
        //    return result;
        //}
        [OperationContract]
        public string GetIdentity()
        {
            string contact = System.Web.HttpContext.Current.User.Identity.Name;
            return contact;
        }

    }
}